
const GRID_SIZE = 30;
const BASE_SIZE = GRID_SIZE * 6;
const MAP_SIZE = BASE_SIZE * 2 + GRID_SIZE * 3;
const DICE_SIZE = 100;
const DICE_X = MAP_SIZE + 40;
const DICE_Y = (MAP_SIZE - DICE_SIZE) / 2;

const Constants = {
  GRID_SIZE,
  BASE_SIZE,
  MAP_SIZE,
  DICE_SIZE,
  DICE_X,
  DICE_Y,
  SYMBOLS: [
    'R', 'G', 'Y', 'B',
  ],
  SIDES: {
    'R': '红方', 'G': '绿方', 'Y': '黄方', 'B': '蓝方',
  },
  COLORS: {
    'R': 'red', 'G': 'green', 'Y': 'yellow', 'B': 'blue',
  },
  CHESS_COLORS: {
    'R': 'darkred', 'G': 'darkgreen', 'Y': 'orange', 'B': 'darkblue',
  },
  CHESS_MOVE_COLORS: {
    'R': 'pink', 'G': 'lime', 'Y': 'gold', 'B': 'cyan',
  },
  // 主路位置
  GRID_POSITIONS: [
    { x: BASE_SIZE + GRID_SIZE * -6, y: 6 * GRID_SIZE }, // 0
    { x: BASE_SIZE + GRID_SIZE * -5, y: 6 * GRID_SIZE }, // 1
    { x: BASE_SIZE + GRID_SIZE * -4, y: 6 * GRID_SIZE }, // 2
    { x: BASE_SIZE + GRID_SIZE * -3, y: 6 * GRID_SIZE }, // 3
    { x: BASE_SIZE + GRID_SIZE * -2, y: 6 * GRID_SIZE }, // 4
    { x: BASE_SIZE + GRID_SIZE * -1, y: 6 * GRID_SIZE }, // 5
    { x: BASE_SIZE + GRID_SIZE * 0, y: 5 * GRID_SIZE }, // 6
    { x: BASE_SIZE + GRID_SIZE * 0, y: 4 * GRID_SIZE }, // 7
    { x: BASE_SIZE + GRID_SIZE * 0, y: 3 * GRID_SIZE }, // 8
    { x: BASE_SIZE + GRID_SIZE * 0, y: 2 * GRID_SIZE }, // 9
    { x: BASE_SIZE + GRID_SIZE * 0, y: 1 * GRID_SIZE }, // 10
    { x: BASE_SIZE + GRID_SIZE * 0, y: 0 * GRID_SIZE }, // 11
    { x: BASE_SIZE + GRID_SIZE * 1, y: 0 * GRID_SIZE }, // 12
    { x: BASE_SIZE + GRID_SIZE * 2, y: 0 * GRID_SIZE }, // 13
    { x: BASE_SIZE + GRID_SIZE * 2, y: 1 * GRID_SIZE }, // 14
    { x: BASE_SIZE + GRID_SIZE * 2, y: 2 * GRID_SIZE }, // 15
    { x: BASE_SIZE + GRID_SIZE * 2, y: 3 * GRID_SIZE }, // 16
    { x: BASE_SIZE + GRID_SIZE * 2, y: 4 * GRID_SIZE }, // 17
    { x: BASE_SIZE + GRID_SIZE * 2, y: 5 * GRID_SIZE }, // 18
    { x: BASE_SIZE + GRID_SIZE * 3, y: 6 * GRID_SIZE }, // 19
    { x: BASE_SIZE + GRID_SIZE * 4, y: 6 * GRID_SIZE }, // 20
    { x: BASE_SIZE + GRID_SIZE * 5, y: 6 * GRID_SIZE }, // 21
    { x: BASE_SIZE + GRID_SIZE * 6, y: 6 * GRID_SIZE }, // 22
    { x: BASE_SIZE + GRID_SIZE * 7, y: 6 * GRID_SIZE }, // 23
    { x: BASE_SIZE + GRID_SIZE * 8, y: 6 * GRID_SIZE }, // 24
    { x: BASE_SIZE + GRID_SIZE * 8, y: 7 * GRID_SIZE }, // 25
    { x: BASE_SIZE + GRID_SIZE * 8, y: 8 * GRID_SIZE }, // 26
    { x: BASE_SIZE + GRID_SIZE * 7, y: 8 * GRID_SIZE }, // 27
    { x: BASE_SIZE + GRID_SIZE * 6, y: 8 * GRID_SIZE }, // 28
    { x: BASE_SIZE + GRID_SIZE * 5, y: 8 * GRID_SIZE }, // 29
    { x: BASE_SIZE + GRID_SIZE * 4, y: 8 * GRID_SIZE }, // 30
    { x: BASE_SIZE + GRID_SIZE * 3, y: 8 * GRID_SIZE }, // 31
    { x: BASE_SIZE + GRID_SIZE * 2, y: 9 * GRID_SIZE }, // 32
    { x: BASE_SIZE + GRID_SIZE * 2, y: 10 * GRID_SIZE }, // 33
    { x: BASE_SIZE + GRID_SIZE * 2, y: 11 * GRID_SIZE }, // 34
    { x: BASE_SIZE + GRID_SIZE * 2, y: 12 * GRID_SIZE }, // 35
    { x: BASE_SIZE + GRID_SIZE * 2, y: 13 * GRID_SIZE }, // 36
    { x: BASE_SIZE + GRID_SIZE * 2, y: 14 * GRID_SIZE }, // 37
    { x: BASE_SIZE + GRID_SIZE * 1, y: 14 * GRID_SIZE }, // 38
    { x: BASE_SIZE + GRID_SIZE * 0, y: 14 * GRID_SIZE }, // 39
    { x: BASE_SIZE + GRID_SIZE * 0, y: 13 * GRID_SIZE }, // 40
    { x: BASE_SIZE + GRID_SIZE * 0, y: 12 * GRID_SIZE }, // 41
    { x: BASE_SIZE + GRID_SIZE * 0, y: 11 * GRID_SIZE }, // 42
    { x: BASE_SIZE + GRID_SIZE * 0, y: 10 * GRID_SIZE }, // 43
    { x: BASE_SIZE + GRID_SIZE * 0, y: 9 * GRID_SIZE }, // 44
    { x: BASE_SIZE + GRID_SIZE * -1, y: 8 * GRID_SIZE }, // 45
    { x: BASE_SIZE + GRID_SIZE * -2, y: 8 * GRID_SIZE }, // 46
    { x: BASE_SIZE + GRID_SIZE * -3, y: 8 * GRID_SIZE }, // 47
    { x: BASE_SIZE + GRID_SIZE * -4, y: 8 * GRID_SIZE }, // 48
    { x: BASE_SIZE + GRID_SIZE * -5, y: 8 * GRID_SIZE }, // 49
    { x: BASE_SIZE + GRID_SIZE * -6, y: 8 * GRID_SIZE }, // 50
    { x: BASE_SIZE + GRID_SIZE * -6, y: 7 * GRID_SIZE }, // 51
  ],
  // 颜色通道位置
  COLOR_TUNNELS: {
    'R': [
      { x: GRID_SIZE, y: BASE_SIZE }, // 0
      { x: GRID_SIZE, y: BASE_SIZE + GRID_SIZE }, // 52
      { x: GRID_SIZE * 2, y: BASE_SIZE + GRID_SIZE }, // 53
      { x: GRID_SIZE * 3, y: BASE_SIZE + GRID_SIZE }, // 54
      { x: GRID_SIZE * 4, y: BASE_SIZE + GRID_SIZE }, // 55
      { x: GRID_SIZE * 5, y: BASE_SIZE + GRID_SIZE }, // 56
      { x: GRID_SIZE * 6, y: BASE_SIZE + GRID_SIZE }, // -2
    ],
    'G': [
      { x: BASE_SIZE + GRID_SIZE * 2, y: GRID_SIZE * 1 }, // 0
      { x: BASE_SIZE + GRID_SIZE, y: GRID_SIZE * 1 }, // 52
      { x: BASE_SIZE + GRID_SIZE, y: GRID_SIZE * 2 }, // 53
      { x: BASE_SIZE + GRID_SIZE, y: GRID_SIZE * 3 }, // 54
      { x: BASE_SIZE + GRID_SIZE, y: GRID_SIZE * 4 }, // 55
      { x: BASE_SIZE + GRID_SIZE, y: GRID_SIZE * 5 }, // 56
      { x: BASE_SIZE + GRID_SIZE, y: GRID_SIZE * 6 }, // -2
    ],
    'Y': [
      { x: BASE_SIZE + GRID_SIZE * 7, y: BASE_SIZE + GRID_SIZE * 2 }, // 0
      { x: BASE_SIZE + GRID_SIZE * 7, y: BASE_SIZE + GRID_SIZE * 1 }, // 52
      { x: BASE_SIZE + GRID_SIZE * 6, y: BASE_SIZE + GRID_SIZE * 1 }, // 53
      { x: BASE_SIZE + GRID_SIZE * 5, y: BASE_SIZE + GRID_SIZE * 1 }, // 54
      { x: BASE_SIZE + GRID_SIZE * 4, y: BASE_SIZE + GRID_SIZE * 1 }, // 55
      { x: BASE_SIZE + GRID_SIZE * 3, y: BASE_SIZE + GRID_SIZE * 1 }, // 56
      { x: BASE_SIZE + GRID_SIZE * 2, y: BASE_SIZE + GRID_SIZE * 1 }, // -2
    ],
    'B': [
      { x: BASE_SIZE, y: BASE_SIZE + GRID_SIZE * 7  }, // 0
      { x: BASE_SIZE + GRID_SIZE, y: BASE_SIZE + GRID_SIZE * 7 }, // 52
      { x: BASE_SIZE + GRID_SIZE, y: BASE_SIZE + GRID_SIZE * 6 }, // 53
      { x: BASE_SIZE + GRID_SIZE, y: BASE_SIZE + GRID_SIZE * 5 }, // 54
      { x: BASE_SIZE + GRID_SIZE, y: BASE_SIZE + GRID_SIZE * 4 }, // 55
      { x: BASE_SIZE + GRID_SIZE, y: BASE_SIZE + GRID_SIZE * 3 }, // 56
      { x: BASE_SIZE + GRID_SIZE, y: BASE_SIZE + GRID_SIZE * 2 }, // -2
    ],
  },
  // 基地位置
  BASE_POSITIONS: {
    'R': { x: 0, y: 0 },
    'G': { x: BASE_SIZE + 3 * GRID_SIZE, y: 0 },
    'Y': { x: BASE_SIZE + 3 * GRID_SIZE, y: BASE_SIZE + 3 * GRID_SIZE },
    'B': { x: 0, y: BASE_SIZE + 3 * GRID_SIZE },
  },
  // 棋子初始位置
  CHESS_BASE_POSITIONS: {
    'R': [
      { x: GRID_SIZE, y: GRID_SIZE },
      { x: GRID_SIZE * 4, y: GRID_SIZE },
      { x: GRID_SIZE, y: GRID_SIZE * 4 },
      { x: GRID_SIZE * 4, y: GRID_SIZE * 4 },
    ],
    'G': [
      { x: BASE_SIZE + 3 * GRID_SIZE + GRID_SIZE, y: GRID_SIZE },
      { x: BASE_SIZE + 3 * GRID_SIZE + GRID_SIZE * 4, y: GRID_SIZE },
      { x: BASE_SIZE + 3 * GRID_SIZE + GRID_SIZE, y: GRID_SIZE * 4 },
      { x: BASE_SIZE + 3 * GRID_SIZE + GRID_SIZE * 4, y: GRID_SIZE * 4 },
    ],
    'Y': [
      { x: BASE_SIZE + 3 * GRID_SIZE + GRID_SIZE, y: BASE_SIZE + 3 * GRID_SIZE + GRID_SIZE },
      { x: BASE_SIZE + 3 * GRID_SIZE + GRID_SIZE * 4, y: BASE_SIZE + 3 * GRID_SIZE + GRID_SIZE },
      { x: BASE_SIZE + 3 * GRID_SIZE + GRID_SIZE, y: BASE_SIZE + 3 * GRID_SIZE + GRID_SIZE * 4 },
      { x: BASE_SIZE + 3 * GRID_SIZE + GRID_SIZE * 4, y: BASE_SIZE + 3 * GRID_SIZE + GRID_SIZE * 4 },
    ],
    'B': [
      { x: GRID_SIZE, y: BASE_SIZE + 3 * GRID_SIZE + GRID_SIZE },
      { x: GRID_SIZE * 4, y: BASE_SIZE + 3 * GRID_SIZE + GRID_SIZE },
      { x: GRID_SIZE, y: BASE_SIZE + 3 * GRID_SIZE + GRID_SIZE * 4 },
      { x: GRID_SIZE * 4, y: BASE_SIZE + 3 * GRID_SIZE + GRID_SIZE * 4 },
    ],
  },
  // 终点位置（三角形）
  COLOR_ENDPOINTS: {
    'R': [
      { x: BASE_SIZE, y: BASE_SIZE },
      { x: BASE_SIZE, y: BASE_SIZE + GRID_SIZE * 3 },
      { x: BASE_SIZE + GRID_SIZE * 3 / 2, y: BASE_SIZE + GRID_SIZE * 3 / 2 },
      { x: BASE_SIZE, y: BASE_SIZE },
    ],
    'G': [
      { x: BASE_SIZE + GRID_SIZE * 3, y: BASE_SIZE },
      { x: BASE_SIZE, y: BASE_SIZE },
      { x: BASE_SIZE + GRID_SIZE * 3 / 2, y: BASE_SIZE + GRID_SIZE * 3 / 2 },
      { x: BASE_SIZE + GRID_SIZE * 3, y: BASE_SIZE },
    ],
    'Y': [
      { x: BASE_SIZE + GRID_SIZE * 3, y: BASE_SIZE + GRID_SIZE * 3 },
      { x: BASE_SIZE + GRID_SIZE * 3, y: BASE_SIZE },
      { x: BASE_SIZE + GRID_SIZE * 3 / 2, y: BASE_SIZE + GRID_SIZE * 3 / 2 },
      { x: BASE_SIZE + GRID_SIZE * 3, y: BASE_SIZE + GRID_SIZE * 3 },
    ],
    'B': [
      { x: BASE_SIZE, y: BASE_SIZE + GRID_SIZE * 3 },
      { x: BASE_SIZE + GRID_SIZE * 3, y: BASE_SIZE + GRID_SIZE * 3 },
      { x: BASE_SIZE + GRID_SIZE * 3 / 2, y: BASE_SIZE + GRID_SIZE * 3 / 2 },
      { x: BASE_SIZE, y: BASE_SIZE + GRID_SIZE * 3 },
    ],
  },
  TOTAL_GRIDS: 57, // 棋子总共可行走的格子数
  GUARD_POSITIONS: [
    1, 9, 14, 22, 27, 35, 40, 48
  ],
  // 是否处于颜色通道
  isInTunnel(pos) {
    return pos >= Constants.GRID_POSITIONS.length - 1 &&
      pos <= Constants.TOTAL_GRIDS - 1;
  },
  // 己方位置对应的颜色通道下标
  priPos2ClrIdx(pos) {
    if (pos === -1 || pos === -2) return pos;
    // 己方起始位置前一格不能走到，要 -1
    // 颜色通道第一格为起点位置，第二格才是真正的通道，要 +1
    return pos - (this.GRID_POSITIONS.length - 1) + 1;
  },
  priPos2PubPos(pos, side, isColorPubPos = false) {
    if (pos === -1 || pos === -2) return pos;
    if (pos >= this.GRID_POSITIONS.length - 1) { // 颜色通道
      if (isColorPubPos) { // 颜色通道对应的普通格子
        return this.priPos2ClrIdx(pos) + this.GRID_POSITIONS.length - 1;
      }

      return this.priPos2ClrIdx(pos);
    } else { // 主路
      const side_index = this.SYMBOLS.indexOf(side);
      return (pos + side_index * 13 + 1) % this.GRID_POSITIONS.length;
    }
  },
};

export default Constants;
